export /**
 * @desc 将毫秒转换为 HH:mm:ss.SSS 格式
 * @param {number} ms - 毫秒数
 * @param {boolean} [showMs=true] - 是否显示毫秒（默认显示）
 * @returns {string} 格式化后的时间字符串
 */
function formatTimeFromMs(ms, showMs = false) {
  if (typeof ms !== 'number' || isNaN(ms) || ms < 0) return '00:00:00'

  const totalSeconds = Math.floor(ms / 1000)
  const hours = Math.floor(totalSeconds / 3600)
  const minutes = Math.floor((totalSeconds % 3600) / 60)
  const seconds = totalSeconds % 60
  const milliseconds = ms % 1000

  const pad = (num, size = 2) => String(num).padStart(size, '0')

  return showMs
    ? `${pad(hours)}:${pad(minutes)}:${pad(seconds)}.${String(milliseconds).padStart(3, '0')}`
    : `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`
}
